'''
执行sql脚本
语句参考
增：insert into stuinfo (id,name) values (1,'john');
删：delete from stuinfo where id =1;
改：update stuinfo set name='lilei' where id =1;
查：select * from stuinfo;
'''
import pymysql

from utils.config import sqlDb


class SqlUtils:
    def __init__(self):
        # 将连接对象和游标都保存成实例属性
        self.conn = pymysql.connect(host=sqlDb['host'], port=sqlDb['port'], user=sqlDb['user'],
                                    password=sqlDb['password'], db=sqlDb['db_name'])
        # 游标
        self.cur = self.conn.cursor()

    # 执行sql(增、删、改)
    def executeSql(self, sqlparams):
        # 执行sql
        result = self.cur.execute(sqlparams)
        # 提交给连接对象
        self.conn.commit()
        # 关闭连接
        self.conn.close()
        return result


if __name__ == '__main__':
    # 测试
    sql = 'select deck_name from Card_deck where id=1'
    result = SqlUtils().executeSql(sql)
    print(result)
